import ij.IJ;
import ij.ImagePlus;
import ij.gui.GenericDialog;
import ij.gui.NewImage;
import ij.plugin.PlugIn;

public class Trajectory_NewImage implements PlugIn {

	static String title = "Trajectories";
	static int w = 400;
	static int h = 300;
	static boolean whiteBackground = false;
	
	static String message =
		"Use ImageJ's polyline tool to draw a trajectory in this image.\n" +
		"Then run plugin " + Trajectory_Add.class.getSimpleName() +
		" to add this trajectory.\n" +
		"Repeat this for additional trajectories. Finally, use plugins\n" + 
		Trajectory_ListAll.class.getSimpleName() + " or " + 
		Trajectory_ShowAsStack.class.getSimpleName() + "\n" +
		"to output or save the trajectory set.\n" +
		"Use " + Trajectory_ClearAll.class.getSimpleName() +
		" to remove all trajectories.";

	public void run(String arg0) {
		if (!getParameters()) {
			return;
		}
		int fill = (whiteBackground) ? NewImage.FILL_WHITE
				: NewImage.FILL_BLACK;
		ImagePlus im = NewImage.createRGBImage(title, w, h, 1, fill);
		im.show();
		IJ.showMessage(message);
	}

	boolean getParameters() {
		GenericDialog gd = new GenericDialog("Create trajectory image");
		gd.addStringField("title", title);
		gd.addNumericField("width", w, 0);
		gd.addNumericField("height", h, 0);
		gd.addCheckbox("white background", whiteBackground);
		gd.showDialog();
		if (gd.wasCanceled()) {
			return false;
		}
		title = gd.getNextString();
		w = (int) gd.getNextNumber();
		h = (int) gd.getNextNumber();
		whiteBackground = gd.getNextBoolean();
		return true;
	}

}
